from selenium import webdriver
import time
from selenium.webdriver.support.wait import WebDriverWait

# driver = webdriver.Chrome("C:/Users/EDZ/AppData/Local/Google/Chrome/Application/chromedriver.exe")

# 声明浏览器
browser = webdriver.Chrome()

# 找到html文件并打开
Path_name = 'D:/Python学习-100天/Day50/selenium.html'

browser.get(Path_name)

# 将浏览器最大化
time.sleep(2)
browser.maximize_window()

# 查找元素并操作
time.sleep(2)
User_name = browser.find_element_by_css_selector('div#signup input[name="username"]').send_keys('rabbit')
time.sleep(2)
Pass_word = browser.find_element_by_css_selector('div#signup input[name="password"]').send_keys('love')
time.sleep(2)
Confirm_button = browser.find_element_by_css_selector('div#signup input.sub').click()
# time.sleep(5)


# 显示等待
result = WebDriverWait(browser, 5, 0.5).until(
    lambda x: x.find_element_by_css_selector("div#signup p")).text

if result == "注册成功":
    print("注册成功")
else:
    print("注册失败")

# 关闭浏览器
browser.quit()
